home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu / asembler.arc / DO0.C < prev    next >
Text File  |  1987-12-09  |  3KB  |  162 lines

  1. /*
  2.  *    MC6800/02 specific processing
  3.  */
  4.  
  5. /* addressing modes */
  6. #define IMMED    0    /* immediate */
  7. #define IND    1    /* indexed */
  8. #define OTHER    2    /* NOTA */
  9.  
  10. /*
  11.  *    localinit --- machine specific initialization
  12.  */
  13. localinit()
  14. {
  15. }
  16.  
  17. /*
  18.  *    do_op --- process mnemonic
  19.  *
  20.  *    Called with the base opcode and it's class. Optr points to
  21.  *    the beginning of the operand field.
  22.  */
  23. do_op(opcode,class)
  24. int opcode;    /* base opcode */
  25. int class;    /* mnemonic class */
  26. {
  27.     int    dist;    /* relative branch distance */
  28.     int    amode;    /* indicated addressing mode */
  29.     char    *peek;
  30.  
  31.     /* guess at addressing mode */
  32.     peek = Optr;
  33.     amode = OTHER;
  34.     while( !delim(*peek) && *peek != EOS)  /* check for comma in operand field */
  35.         if( *peek++ == ',' ){
  36.             amode = IND;
  37.             break;
  38.             }
  39.     if( *Optr == '#' ) amode = IMMED;
  40.  
  41.     switch(class){
  42.         case INH:            /* inherent addressing */
  43.             emit(opcode);
  44.             return;
  45.         case GEN:            /* general addressing */
  46.             do_gen(opcode,amode);
  47.             return;
  48.         case REL:            /* relative branches */
  49.             eval();
  50.             dist = Result - (Pc+2);
  51.             emit(opcode);
  52.             if( (dist >127 || dist <-128) && Pass==2){
  53.                 error("Branch out of Range");
  54.                 emit(lobyte(-2));
  55.                 return;
  56.                 }
  57.             emit(lobyte(dist));
  58.             return;
  59.         case NOIMM:
  60.             if( amode == IMMED){
  61.                 error("Immediate Addressing Illegal");
  62.                 return;
  63.                 }
  64.             if((opcode == 0x8D) && (amode == IND)){
  65.                 Cycles-=2;
  66.                 }
  67.             do_gen(opcode,amode);
  68.  
  69.             return;
  70.         case LONGIMM:
  71.             if( amode == IMMED ){
  72.                 emit(opcode);
  73.                 Optr++;
  74.                 eval();
  75.                 eword(Result);
  76.                 return;
  77.                 }
  78.             do_gen(opcode,amode);
  79.             return;
  80.         case GRP2:
  81.             if( amode == IND ){
  82.                 Cycles++;
  83.                 do_indexed(opcode);
  84.                 return;
  85.                 }
  86.             /* extended addressing */
  87.             eval();
  88.             emit(opcode+0x10);
  89.             eword(Result);
  90.             return;
  91.         default:
  92.             fatal("Error in Mnemonic table");
  93.         }
  94. }
  95.  
  96. /*
  97.  *    do_gen --- process general addressing modes
  98.  */
  99. do_gen(op,mode)
  100. int    op;
  101. int    mode;
  102. {
  103.     if( mode == IMMED){
  104.         Optr++;
  105.         emit(op);
  106.         eval();
  107.         emit(lobyte(Result));
  108.         return;
  109.         }
  110.     else if( mode == IND ){
  111.         Cycles+=3;
  112.         do_indexed(op+0x20);
  113.         return;
  114.         }
  115.     else if( mode == OTHER){
  116.         eval();
  117.         if(Force_word){
  118.             emit(op+0x30);
  119.             eword(Result);
  120.             Cycles+=2;
  121.             return;
  122.             }
  123.         if(Force_byte){
  124.             emit(op+0x10);
  125.             emit(lobyte(Result));
  126.             Cycles++;
  127.             return;
  128.             }
  129.         if(Result>=0 && Result <=0xFF){
  130.             emit(op+0x10);
  131.             emit(lobyte(Result));
  132.             Cycles++;
  133.             return;
  134.             }
  135.         else {
  136.             emit(op+0x30);
  137.             eword(Result);
  138.             Cycles+=2;
  139.             return;
  140.             }
  141.         }
  142.     else {
  143.         error("Unknown Addressing Mode");
  144.         return;
  145.         }
  146. }
  147.  
  148. /*
  149.  *    do_indexed --- handle all wierd stuff for indexed addressing
  150.  */
  151. do_indexed(op)
  152. int op;
  153. {
  154.     emit(op);
  155.     eval();
  156.     if( mapdn(*++Optr) != 'x' )
  157.         warn("Indexed Addressing Assumed");
  158.     if( Result < 0 || Result > 255)
  159.         warn("Value Truncated");
  160.     emit(lobyte(Result));
  161. }
  162.